<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
need_auth('market');

$id = abs(intval($_GET['id']));
$bd = Table::Fetch('bd', $id);

if ( $_POST && $id==$_POST['id'] && $bd) {
	$table = new Table('bd', $_POST);
	$table->create_time = time();
	$table->password = Zbd::GenPassword($table->password);
	$table->city_id = abs(intval($table->city_id));
	$table->enable = (strtoupper($table->enable)=='Y') ? 'Y' : 'N';
	$table->gender = (strtoupper($table->gender)=='M') ? 'M' : 'F';

	$up_array = array(
		'username', 'password', 'realname', 'phone' , 'email', 'qq',
		'gender', 'city_id', 'enable', 'bank_name', 'bank_user', 'bank_no', 'create_time',
	);

	if ($table->password ) {
		$table->password = ZBd::GenPassword($table->password);
		$up_array[] = 'password';
	}
	$flag = $table->update( $up_array );
	if ( $flag ) {
		Session::Set('notice', '修改业务信息成功');
		redirect( WEB_ROOT . "/manage/bd/edit.php?id={$id}");
	}
	Session::Set('error', '修改业务信息失败');
	$partner = $_POST;
}

include template('manage_bd_edit');
